﻿using UnityEngine;
using System.Collections;

public class LevelManager : MonoBehaviour {

	private float worldScrollSpeed = 8.0f;
	private float totalDistance = 0.0f;
	private SceneryLayer[] scenery;
	/// <summary>
	/// Gets the total distance.
	/// </summary>
	/// <value>The total distance.</value>
	public float TotalDistance
	{
		get{ return totalDistance; }
	}

	void Start()
	{
		scenery = GetComponentsInChildren<SceneryLayer> ();
	}
	/// <summary>
	/// Restart this instance.
	/// </summary>
	public void Restart()
	{
		totalDistance = 0.0f;
		foreach (SceneryLayer layer in scenery)
			layer.Restart ();
		foreach (SceneryLayer layer in scenery) 
		{
			if (!layer.isInfinite)
			{
				layer.DisableNextLayer ();
			}
		}
	}
	/// <summary>
	/// Update this instance.
	/// </summary>
	void Update()
	{
		float speed = (GameManager.Game.IsPaused || GameManager.Game.IsGameOver) ? 0.0f : worldScrollSpeed;
		totalDistance += speed * Time.deltaTime;

		foreach(SceneryLayer layer in scenery)
		{
			layer.UpdateBlocks (speed);
		}
	}
}
